<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="disabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="8">
            <a-form-model-item label="项目代号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="equipmentProjectcode">
              <a-input v-model="model.equipmentProjectcode" placeholder="请输入项目代号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入项目名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" v-show="disabled">
            <a-form-model-item label="项目创建人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.createBy"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" v-show="disabled">
            <a-form-model-item label="项目创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.createTime" ></a-input>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="8">
            <a-form-model-item label="项目系列号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="serialNumber">
              <a-input v-model="model.serialNumber" placeholder="请输入项目系列号"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <!-- <a-col :span="8">
            <a-form-model-item label="地图位置" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lonlat">
              <a-input-number v-model="model.lonlat" placeholder="请输入地图位置" style="width: 100%" />
            </a-form-model-item>
          </a-col> -->
          <!-- <a-col :span="8">
            <a-form-model-item label="项目型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="equipmentModel">
              <j-dict-select-tag type="list" v-model="model.equipmentModel" dictCode="equipment_model" placeholder="请选择项目型号" />
            </a-form-model-item>
          </a-col> -->
          <!-- <a-col :span="8">
            <a-form-model-item label="项目编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="code">
              <a-input v-model="model.code" placeholder="请输入项目编号"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="8">
            <a-form-model-item label="项目类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="equipmentType">
              <j-dict-select-tag type="list" v-model="model.equipmentType" dictCode="equipment_type" placeholder="请选择项目类型" />
            </a-form-model-item>
          </a-col>
          
          
          <a-col :span="8">
            <a-form-model-item label="项目建设日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productDate">
              <j-date placeholder="请选择项目建设日期" v-model="model.productDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="8">
            <a-form-model-item label="生产状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productionStatus">
              <j-dict-select-tag type="list" v-model="model.productionStatus" dictCode="production status" placeholder="请选择生产状态" />
            </a-form-model-item>
          </a-col> -->
          <!-- <a-col :span="8">
            <a-form-model-item label="运行状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="runtimeStatus">
              <j-dict-select-tag type="list" v-model="model.runtimeStatus" dictCode="runtime_status" placeholder="请选择运行状态" />
            </a-form-model-item>
          </a-col> -->
          <a-col :span="8">
            <a-form-model-item label="交付(验收)日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="acceptanceDate">
              <j-date placeholder="请选择交付(验收)日期" v-model="model.acceptanceDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="质保结束日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="warrantyEnddate">
              <j-date placeholder="请选择质保结束日期" v-model="model.warrantyEnddate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          
          <a-col :span="8">
            <a-form-model-item label="项目区域" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="equipmentArea">
              <j-select-region v-model="model.equipmentArea"  :backRegion="true" :treeOpera="true"> </j-select-region>
              <!-- <a-input v-model="model.equipmentArea" placeholder="请输入项目区域"  ></a-input> -->
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="8">
            <a-form-model-item label="制造商" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productor">
              <a-input v-model="model.productor" placeholder="请输入制造商"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="8">
            <a-form-model-item label="售后服务联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="aftersellContacts">
              <a-input v-model="model.aftersellContacts" placeholder="请输入售后服务联系人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="售后服务电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="phoneWechat">
              <a-input v-model="model.phoneWechat" placeholder="请输入售后服务电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="售后服务邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="email">
              <a-input v-model="model.email" placeholder="请输入售后服务邮箱"  ></a-input>
            </a-form-model-item>
          </a-col>
          
          <a-col :span="8">
            <a-form-model-item label="项目负责人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="manager">
              <a-input v-model="model.manager" placeholder="请输入项目负责人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="8">
            <a-form-model-item label="用户ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customId">
              <a-input v-model="model.customId" placeholder="请输入用户ID"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="8">
            <a-form-model-item label="客户名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customName">
              <a-input v-model="model.customName" placeholder="请输入客户名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="客户地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customAddress">
              <a-input v-model="model.customAddress" placeholder="请输入客户地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          
          <a-col :span="8">
            <a-form-model-item label="客户业务联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contracts">
              <a-input v-model="model.contracts" placeholder="请输入客户业务联系人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="客户联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="phone">
              <a-input v-model="model.phone" placeholder="请输入客户联系电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="PLC品牌与型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="plcBrand">
              <a-input v-model="model.plcBrand" placeholder="请输入PLC品牌与型号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="RDEE品牌与型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rdeeBrand">
              <a-input v-model="model.rdeeBrand" placeholder="请输入RDEE品牌与型号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="RDEE网关型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rdeeRoutetype">
              <a-input v-model="model.rdeeRoutetype" placeholder="请输入RDEE网关型号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="RDEE网关序列号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rdeeRouteserialnumber">
              <a-input v-model="model.rdeeRouteserialnumber" placeholder="请输入RDEE网关序列号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="RDEE网关账号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rdeeRouteaccount">
              <a-input v-model="model.rdeeRouteaccount" placeholder="请输入RDEE网关账号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="RDEE网关账号密码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rdeeRoutepassword">
              <a-input v-model="model.rdeeRoutepassword" placeholder="请输入RDEE网关账号密码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="RDEE流量卡号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rdeeFlownumber">
              <a-input v-model="model.rdeeFlownumber" placeholder="请输入RDEE流量卡号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="RDEE ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rdeeId">
              <a-input v-model="model.rdeeId" placeholder="请输入RDEE ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="RDEE IP	" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rdeeIp">
              <a-input v-model="model.rdeeIp" placeholder="请输入RDEE IP	"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="RDEE MQTT账号密码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rdeeMqtt">
              <a-input v-model="model.rdeeMqtt" placeholder="请输入RDEE MQTT账号密码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="RDEE流量卡到期日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rdeeEnddate">
              <j-date placeholder="请选择RDEE流量卡到期日期" v-model="model.rdeeEnddate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="项目地图位置" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lonlat">
              <a-button @click="dialogMapVisible = true">{{model.lonlatStatus}}</a-button>
              <a-button @click="clearMapData">清除</a-button>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelColRemark" :wrapperCol="wrapperCol" prop="remark">
              <a-textarea v-model="model.remark" placeholder="请输入备注" :rows="6"></a-textarea>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
      
    </j-form-container>
    <j-modal :visible.sync="dialogMapVisible" :fullscreen="true" :lock-scroll="true">
         <map-select style="width: 100%;height:100%;" v-on:mapData="mapData" :data="model"/>
      </j-modal>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import MapSelect from "@/components/Map/select";
  import JModal from '@/components/jeecg/JModal/JModal.vue';
  import JSelectRegion from '@/components/jeecgbiz/JSelectRegion.vue'

  export default {
    name: 'YksEquipmentForm',
    components: {
      JModal,
      MapSelect,
      JSelectRegion
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        dialogMapVisible: false,
        lonlatStatus: "未设置",
        labelCol: {
          xs: { span: 24 },
          sm: { span: 10 },
        },
        labelColRemark: {
          xs: { span: 24},
          sm: { span: 3 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 12 },
        },
        confirmLoading: false,
        validatorRules: {
           code: [
              { required: true, message: '请输入项目编号!'},
           ],
           name: [
              { required: true, message: '请输入项目名称!'},
           ],
          //  serialNumber: [
          //     { required: true, message: '请输入项目系列号!'},
          //  ],
           equipmentType: [
              { required: true, message: '请输入项目类型!'},
           ],
           equipmentProjectcode: [
              { required: true, message: '请输入项目项目代号!'},
           ],
           equipmentModel: [
              { required: true, message: '请输入项目型号!'},
           ],
           productDate: [
              { required: true, message: '请输入出厂日期!'},
           ],
           productionStatus: [
              { required: true, message: '请输入生产状态!'},
           ],
           runtimeStatus: [
              { required: true, message: '请输入运行状态!'},
           ],
           acceptanceDate: [
              { required: true, message: '请输入交付(验收)日期!'},
           ],
           warrantyEnddate: [
              { required: true, message: '请输入质保结束日期!'},
           ],
           rdeeEnddate: [
              { required: true, message: '请输入RDEE流量卡到期日期!'},
           ],
           equipmentArea: [
              { required: true, message: '请输入项目区域!'},
           ],
           productor: [
              { required: true, message: '请输入制造商!'},
           ],
           aftersellContacts: [
              { required: true, message: '请输入售后服务联系人!'},
           ],
           phoneWechat: [
              { required: true, message: '请输入联系电话及微信号!'},
           ],
           email: [
              { required: true, message: '请输入邮箱!'},
           ],
           manager: [
              { required: true, message: '请输入项目项目负责人!'},
           ],
           customName: [
              { required: true, message: '请输入客户名称!'},
           ],
           customAddress: [
              { required: true, message: '请输入客户地址!'},
           ],
           contracts: [
              { required: true, message: '请输入业务联系人!'},
           ],
           phone: [
              { required: true, message: '请输入联系电话!'},
           ],
           plcBrand: [
              { required: true, message: '请输入PLC品牌与型号!'},
           ],
           rdeeBrand: [
              { required: true, message: '请输入RDEE品牌与型号!'},
           ],
           rdeeRoutetype: [
              { required: true, message: '请输入RDEE网关型号!'},
           ],
           rdeeRouteserialnumber: [
              { required: true, message: '请输入RDEE网关序列号!'},
           ],
           rdeeRouteaccount: [
              { required: true, message: '请输入RDEE网关账号!'},
           ],
           rdeeRoutepassword: [
              { required: true, message: '请输入RDEE网关账号密码!'},
           ],
           rdeeFlownumber: [
              { required: true, message: '请输入RDEE流量卡号!'},
           ],
           rdeeId: [
              { required: true, message: '请输入RDEE ID!'},
           ],
           rdeeIp: [
              { required: true, message: '请输入RDEE IP	!'},
           ],
           rdeeMqtt: [
              { required: true, message: '请输入RDEE MQTT账号密码!'},
           ],
        },
        url: {
          add: "/dev/yksEquipment/add",
          edit: "/dev/yksEquipment/edit",
          queryById: "/dev/yksEquipment/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      clearMapData() {
        this.model.lonlat = null;
        this.model.lonlatStatus = "未设置";
      },
      mapData(data) {
        this.dialogMapVisible = false;
        if (data) {
          this.model.lonlat = data;
          this.model.lonlatStatus = "已设置";
        }
      },
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        console.log(this.model)
        if (this.model.lonlat) {
          this.model.lonlatStatus = "已设置";
        } else {
          this.model.lonlatStatus = "未设置";
        }
        this.visible = true;
      },
      detail (record) {
        this.model = Object.assign({}, record);
        console.log(this.model)
        if (this.model.lonlat) {
          this.model.lonlatStatus = "已设置";
        } else {
          this.model.lonlatStatus = "未设置";
        }
        this.visible = true;
        this.disabled=true
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>